<template>
  <div>
    <TableData :tableList="list" :pagination="pagination" @changePagination="changePagination" />
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import TableData from './components/userView/tableData.vue'
import type { TTable } from './components/userView/type.dict'
import { listWechatUsers } from '@/api/wechat.api'

const list = ref<TTable[]>([])
const pagination = ref<{
  total: number
  current: number
  pageSize: number
}>({
  total: 0,
  current: 1,
  pageSize: 10,
})
const getLis = async () => {
  const res = await listWechatUsers({ page: pagination.value.current, size: pagination.value.pageSize })
  if (res.code === 200 && res.data) {
    pagination.value.total = res.data.total
    list.value = res.data.list.map((u) => ({
      id: u._id,
      nickname: u.nickname ?? '',
      cover: u.cover ?? null,
      all_points: u.all_points ?? 0,
      use_points: u.use_points ?? 0,
      openid: u._openid ?? '',
      status: u.status ?? '',
      updateBy: u.updatedAt,
    })) as TTable[]
  }
}
const changePagination = (e: { current: number; pageSize: number }) => {
  pagination.value.current = e.current
  pagination.value.pageSize = e.pageSize
  getLis()
}
onMounted(() => {
  getLis()
})
</script>
